package com.ryujung.array.leetcode_11;

/*
 * @lc app=leetcode.cn id=11 lang=java
 *
 * [11] 盛最多水的容器
 */

// @lc code=start
class Solution {

    /**
     * 双指针法
     */
    public static int maxArea(int[] height) {
        int left = 0, right = height.length - 1;
        int max = 0;
        while (left < right) {
            int l = height[left];
            int r = height[right];
            max = Math.max(max, (right - left) * Math.min(height[left], height[right]));
            if (l < r) {
                left++;
            } else {
                right--;
            }
        }
        return max;
    }

    public static void main(String[] args) {
        // 49
        System.out.println(maxArea(new int[] { 1, 8, 6, 2, 5, 4, 8, 3, 7 }));
    }
}
// @lc code=end
